/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Button.java
 *
 * Created on Mar 2, 2011, 1:47:45 PM
 */

package imat;

import java.awt.event.MouseEvent;

/**
 *
 * @author andlu
 */
public class ImageButton extends ImagePanel {

    private String imageBackground = "";
    private String imageBackgroundDown = "";
    private String imageLeftStr = "";
    private String imageLeftDownStr = "";
    private String imageRightStr = "";
    private String imageRightDownStr = "";

    private String actionCommand = "";

    /** Creates new form Button */
    public ImageButton() {
        initComponents();
    }

    public String getActionCommand() {
        return actionCommand;
    }

    public void setActionCommand(String actionCommand) {
        this.actionCommand = actionCommand;
    }

    

    public void setText(String text) {
        this.text.setText(text);
    }

    public String getText() {
        return this.text.getText();
    }

    public void setImageLeft(String img) {
        this.imageLeft.setImage(img);
        imageLeftStr = img;
    }

    public String getImageLeft() {
        return imageLeftStr;
    }

    public void setImageLeftDown(String img) {
        imageLeftDownStr = img;
    }

    public String getImageLeftDown() {
        return imageLeftDownStr;
    }

    public void setImageRight(String img) {
        this.imageRight.setImage(img);
        imageRightStr = img;
    }

    public String getImageRight() {
        return imageRightStr;
    }

    public void setImageRightDown(String img) {
        imageRightDownStr = img;
    }

    public String getImageRightDown() {
        return imageRightDownStr;
    }

    public void setImageBackground(String img) {
        this.setImage(img);
        imageBackground = img;
    }

    public String getImageBackground() {
        return imageBackground;
    }

    public void setImageBackgroundDown(String img) {
        if (img.isEmpty()) {
            img = imageBackground;
        }
        this.imageBackgroundDown = img;
    }

    public String getImageBackgroundDown() {
        return imageBackgroundDown;
    }

    public boolean isButtonClicked(MouseEvent evt) {
        double x = evt.getPoint().getX();
        double y = evt.getPoint().getY();

        this.setImage(imageBackground);
        this.imageLeft.setImage(imageLeftStr);
        this.imageRight.setImage(imageRightStr);
        this.repaint();
        if (evt.getButton() == MouseEvent.BUTTON1 &&
                (x >= 0 && x <= this.getWidth()) &&
                (y >= 0 && y <= this.getHeight())) {
            
            return true;
        }
        return false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        text = new javax.swing.JLabel();
        imageLeft = new imat.ImagePanel();
        imageRight = new imat.ImagePanel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(ImageButton.class);
        setImage(resourceMap.getString("Form.image")); // NOI18N
        setOpaque(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
        });
        setLayout(new java.awt.BorderLayout());

        text.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        text.setText(resourceMap.getString("text.text")); // NOI18N
        text.setName("text"); // NOI18N
        add(text, java.awt.BorderLayout.CENTER);

        imageLeft.setName("imageLeft"); // NOI18N
        imageLeft.setOpaque(false);
        imageLeft.setPreferredSize(new java.awt.Dimension(10, 41));

        javax.swing.GroupLayout imageLeftLayout = new javax.swing.GroupLayout(imageLeft);
        imageLeft.setLayout(imageLeftLayout);
        imageLeftLayout.setHorizontalGroup(
            imageLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        imageLeftLayout.setVerticalGroup(
            imageLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 110, Short.MAX_VALUE)
        );

        add(imageLeft, java.awt.BorderLayout.WEST);

        imageRight.setName("imageRight"); // NOI18N
        imageRight.setOpaque(false);
        imageRight.setPreferredSize(new java.awt.Dimension(10, 41));

        javax.swing.GroupLayout imageRightLayout = new javax.swing.GroupLayout(imageRight);
        imageRight.setLayout(imageRightLayout);
        imageRightLayout.setHorizontalGroup(
            imageRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        imageRightLayout.setVerticalGroup(
            imageRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 110, Short.MAX_VALUE)
        );

        add(imageRight, java.awt.BorderLayout.EAST);
    }// </editor-fold>//GEN-END:initComponents

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
        if (evt.getButton() == MouseEvent.BUTTON1) {
            this.setImage(imageBackgroundDown);
            this.imageLeft.setImage(imageLeftDownStr);
            this.imageRight.setImage(imageRightDownStr);
        }
    }//GEN-LAST:event_formMousePressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private imat.ImagePanel imageLeft;
    private imat.ImagePanel imageRight;
    protected javax.swing.JLabel text;
    // End of variables declaration//GEN-END:variables



}
